﻿namespace PrismEx.Fixtures.Base
{
    using System.Collections.Generic;

    using NUnit.Framework;

    using PrismEx.Base;

    using Stump;

    [TestFixture]
    public class ObservableFixture : TestFixtureBase<ObservableFixture.ObservableMock>
    {
        private List<string> changes = new List<string>();

        public override void Given()
        {
            this.TestDomain = new TestDomain<ObservableMock>(new ObservableMock());
            this.TestDomain.Subject.PropertyChanged += (sender, args) => changes.Add(args.PropertyName);
        }

        public override void When()
        {
            this.TestDomain.Subject.Property1 = "Value1";
            this.TestDomain.Subject.Property2 = "Value2";
        }

        [Then(Description = "Property changed should have been raised for each of the properties changed")]
        public void Should()
        {
            Assert.That(changes.Count, Is.EqualTo(2));
            Assert.That(changes[0], Is.EqualTo("Property1"));
            Assert.That(changes[1], Is.EqualTo("Property2"));
        }

        public class ObservableMock : Observable
        {
            private string property1;

            private string property2;

            public string Property1
            {
                get
                {
                    return property1;
                }
                set
                {
                    property1 = value;
                    this.OnPropertyChanged("Property1");
                }
            }

            public string Property2
            {
                get
                {
                    return property2;
                }
                set
                {
                    property2 = value;
                    this.OnPropertyChanged(() => this.Property2);
                }
            }
        }
    }
}